package com.smmisia.article.core;

import com.smmisia.article.entity.Article;
import com.smmisia.article.entity.Score;
import com.smmisia.article.mapper.ArticleMapper;
import com.smmisia.article.mapper.ScoreMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class Recommend {

    @Autowired
    private ArticleMapper articleMapper;

    @Autowired
    private ScoreMapper scoreMapper;

    public List<Article> userCfRecommend(int userId) {
        List<Score> articleScoreList = scoreMapper.selectList(null);
        List<Integer> recommendations = UserCF.recommend(userId, articleScoreList);
        List<Article> articleList = articleMapper.selectList(null);
        List<Article> list = articleList
                .stream()
                .filter(e -> recommendations.contains(e.getId()))
                .collect(Collectors.toList());
        return list;
    }


//    public static List<Article>  itemCfRecommend(int itemId){
//        List<ArticleScore> data= FileDataSource.getData();
//        List<Integer> recommendations = ItemCF.recommend(itemId, data);
//        List<Integer> list = FileDataSource.getItemData()
//                .stream()
//                .filter(e -> recommendations.contains(e.getId()))
//                .collect(Collectors.toList());
//        return list;
//    }


}
